Conditions | 1 |
Paths | 1 |
Total Lines | 111 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | var assert = require('chai').assert, |
||
4 | describe('Fact', function(){ |
||
5 | |||
6 | it('Create plain', function(){ |
||
7 | var newFact = new GedcomX.Fact(), |
||
8 | fact = GedcomX.Fact(); |
||
9 | assert.instanceOf(newFact, GedcomX.Fact, 'An instance of Fact is not returned when calling the constructor with new.'); |
||
10 | assert.instanceOf(fact, GedcomX.Fact, 'An instance of Fact is not returned when calling the constructor without new.'); |
||
11 | }); |
||
12 | |||
13 | it('Create with JSON', function(){ |
||
14 | var fact = GedcomX.Fact({ |
||
15 | id: 'fact', |
||
16 | type: 'http://gedcomx.org/Birth', |
||
17 | date: { |
||
18 | original: '1845' |
||
19 | }, |
||
20 | place: { |
||
21 | original: 'Casper, Wyoming' |
||
22 | }, |
||
23 | value: 'Birth value', |
||
24 | qualifiers: [ |
||
25 | { |
||
26 | name: 'http://gedcomx.org/Age', |
||
27 | value: '0' |
||
28 | } |
||
29 | ] |
||
30 | }); |
||
31 | assert.equal(fact.getId(), 'fact'); |
||
32 | assert.equal(fact.getType(), 'http://gedcomx.org/Birth'); |
||
33 | assert.equal(fact.getDate().getOriginal(), '1845'); |
||
34 | assert.equal(fact.getPlace().getOriginal(), 'Casper, Wyoming'); |
||
35 | assert.equal(fact.getValue(), 'Birth value'); |
||
36 | assert.equal(fact.getQualifiers().length, 1); |
||
37 | assert.equal(fact.getQualifiers()[0].getName(), 'http://gedcomx.org/Age'); |
||
38 | assert.equal(fact.getQualifiers()[0].getValue(), '0'); |
||
39 | }); |
||
40 | |||
41 | it('Create with mixed data', function(){ |
||
42 | var fact = GedcomX.Fact({ |
||
43 | id: 'fact', |
||
44 | type: 'http://gedcomx.org/Birth', |
||
45 | date: GedcomX.Date({ |
||
46 | original: '1845' |
||
47 | }), |
||
48 | place: GedcomX.PlaceReference({ |
||
49 | original: 'Casper, Wyoming' |
||
50 | }), |
||
51 | value: 'Birth value', |
||
52 | qualifiers: [ |
||
53 | GedcomX.Qualifier({ |
||
54 | name: 'http://gedcomx.org/Age', |
||
55 | value: '0' |
||
56 | }) |
||
57 | ] |
||
58 | }); |
||
59 | assert.equal(fact.getId(), 'fact'); |
||
60 | assert.equal(fact.getType(), 'http://gedcomx.org/Birth'); |
||
61 | assert.equal(fact.getDate().getOriginal(), '1845'); |
||
62 | assert.equal(fact.getPlace().getOriginal(), 'Casper, Wyoming'); |
||
63 | assert.equal(fact.getValue(), 'Birth value'); |
||
64 | assert.equal(fact.getQualifiers().length, 1); |
||
65 | assert.equal(fact.getQualifiers()[0].getName(), 'http://gedcomx.org/Age'); |
||
66 | assert.equal(fact.getQualifiers()[0].getValue(), '0'); |
||
67 | }); |
||
68 | |||
69 | it('Build', function(){ |
||
70 | var fact = GedcomX.Fact() |
||
71 | .setId('fact') |
||
72 | .setType('http://gedcomx.org/Birth') |
||
73 | .setDate(GedcomX.Date().setOriginal('1845')) |
||
74 | .setPlace(GedcomX.PlaceReference().setOriginal('Casper, Wyoming')) |
||
75 | .setValue('Birth value') |
||
76 | .addQualifier(GedcomX.Qualifier().setName('http://gedcomx.org/Age').setValue('0')); |
||
77 | assert.equal(fact.getId(), 'fact'); |
||
78 | assert.equal(fact.getType(), 'http://gedcomx.org/Birth'); |
||
79 | assert.equal(fact.getDate().getOriginal(), '1845'); |
||
80 | assert.equal(fact.getPlace().getOriginal(), 'Casper, Wyoming'); |
||
81 | assert.equal(fact.getValue(), 'Birth value'); |
||
82 | assert.equal(fact.getQualifiers().length, 1); |
||
83 | assert.equal(fact.getQualifiers()[0].getName(), 'http://gedcomx.org/Age'); |
||
84 | assert.equal(fact.getQualifiers()[0].getValue(), '0'); |
||
85 | }); |
||
86 | |||
87 | it('toJSON', function(){ |
||
88 | var data = { |
||
89 | id: 'fact', |
||
90 | type: 'http://gedcomx.org/Birth', |
||
91 | date: { |
||
92 | original: '1845' |
||
93 | }, |
||
94 | place: { |
||
95 | original: 'Casper, Wyoming' |
||
96 | }, |
||
97 | value: 'Birth value', |
||
98 | qualifiers: [ |
||
99 | { |
||
100 | name: 'http://gedcomx.org/Age', |
||
101 | value: '0' |
||
102 | } |
||
103 | ] |
||
104 | }, fact = GedcomX.Fact(data); |
||
105 | assert.deepEqual(fact.toJSON(), data); |
||
106 | }); |
||
107 | |||
108 | it('constructor does not copy instances', function(){ |
||
109 | var obj1 = GedcomX.Fact(); |
||
110 | var obj2 = GedcomX.Fact(obj1); |
||
111 | assert.strictEqual(obj1, obj2); |
||
112 | }); |
||
113 | |||
114 | }); |